a = 5678
while a != 6174 and len(set(str(a)))!=1:
    b = list(str(a))
    c = int("".join(sorted(b)))
    d = int("".join(sorted(b, reverse=True)))
    a = d-c
    print(a)


